module.exports = options => {
    return async function adminAuth(ctx, next) {
      const url =require('url');
      let pathname = url.parse(ctx.request.url).pathname;
      ctx.state.csrf=ctx.csrf;
      if (ctx.session.userinfo){
        await next();
      } else { 
          if (pathname=='/admin/login' || pathname=='/admin/verify' || pathname=='/admin/dologin'){
            await next();
          } else {
            ctx.redirect('/admin/login');
          }
      }
    };
  };